using System;
using log4net;

namespace Sedna.Utility.Command
{
    public abstract class AbstractCommand : ICommand, IEquatable<AbstractCommand>
	{

		#region Fields

		protected ILog log = LogManager.GetLogger(typeof(AbstractCommand));
		private string description;
        private string name;

		#endregion

		#region Properties

		public string Description
        {
            get { return description; }
            set { description = value; }
        }

        public string Name
        {
            get { return name; }
            set { name = value; }
		}

		#endregion

		public abstract CommandResult Run(string[] parameters);

        protected bool IsParameterAny(String parameter)
        {
            if (String.IsNullOrEmpty(parameter))
            {
                return true;
            }

            return parameter.ToLower().Equals("any");
        }

        #region Equals/Hashcode

        public bool Equals(AbstractCommand abstractCommand)
        {
            if (abstractCommand == null)
            {
                return false;
            }
            return name.ToLower().Equals(abstractCommand.name.ToLower());
        }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(this, obj))
            {
                return true;
            }
            return Equals(obj as AbstractCommand);
        }

        public override int GetHashCode()
        {
            return name != null ? name.ToLower().GetHashCode() : 0;
        }

        #endregion
    
	}
}
